module.exports = () => {
    return async (ctx,next) => {
        let writePath = ['/api/booklist'];

        if(writePath.includes(ctx.path)){
            await next()
        }else{
            //需要校验权限
            let identity = ctx.get('egg-identity');

            try{
                if(identity && identity === 'admin'){
                    await next()
                }else{
                    ctx.status = 401;
                    ctx.body = {
                        code:4,
                        msg:'权限失败'
                    }
                }
            }catch(e){
                ctx.body = {
                    code:0,
                    msg:e
                }
            }
        }
    }
}